﻿using System;
using System.Collections.Generic;

using UnityEngine;


public class VideoCfgData : ImplData
{

	public class VideoCfg
	{
		public string VideoType = "";

		public string urlVideo1 = "";
		public string urlVideo2 = "";

		public string urlAudio1 = "";
		public string urlAudio2 = "";

		public float time = 0; 			

		public string urlImage = "";
		public Vector2 size = Vector2.one; 			// 图片尺寸

		public Vector2 beginPos = Vector2.zero;
		public Vector2 endPos = Vector2.zero;

	}

	private Dictionary<string, VideoCfg> d = new Dictionary<string, VideoCfg> ();

	protected override int Deserialize()
	{

		if (string.IsNullOrEmpty(jsonText))
			return -1;

		data = MiniJSON.Json.Deserialize(jsonText) as Dictionary<string, object>;

		foreach (var item in data) {

			VideoCfg gamecfg = new VideoCfg ();
			Dictionary<string, object> dict = item.Value as Dictionary<string, object>;

			string Typ = dict ["type"] as string;
			gamecfg.VideoType = Typ;

			gamecfg.urlVideo1 = dict ["urlVideo1"] as string;

			gamecfg.urlAudio1 = dict ["urlAudio1"] as string;

			if (Typ == "multi") {
			
				gamecfg.urlVideo2 = dict ["urlVideo2"] as string;
				gamecfg.urlAudio2 = dict ["urlAudio2"] as string;
				gamecfg.time = Convert.ToSingle (dict ["time"]);
				gamecfg.urlImage = dict ["urlImage"] as string;

				Dictionary<string, object> tmp = dict ["beginPos"] as Dictionary<string, object>;
				gamecfg.beginPos.x = Convert.ToSingle (tmp ["x"]);
				gamecfg.beginPos.y = Convert.ToSingle (tmp ["y"]);

				tmp = dict ["endPos"] as Dictionary<string, object>;
				gamecfg.endPos.x = Convert.ToSingle (tmp ["x"]);
				gamecfg.endPos.y = Convert.ToSingle (tmp ["y"]);

				tmp = dict ["imageSize"] as Dictionary<string, object>;
				gamecfg.size.x = Convert.ToSingle (tmp ["x"]);
				gamecfg.size.y = Convert.ToSingle (tmp ["y"]);

			}

			d.Add (item.Key, gamecfg);

		}

		return 0;
	}

	public VideoCfg GetCfg( string id )
	{
		if (d.ContainsKey (id))
			return d [id];
		else
			return null;
	}



}


